<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组去重</title>
</head>

<body>
  <script>
    Array.prototype.unique = function () {
      var obj = {};
      for (let i = 0; i < this.length; i++) {
        const element = this[i];
        if (obj[element] == element) {
          this[i] = this[this.length - 1];
          this.length--;
          i--;
          continue;
        }
        obj[element] = element;
        console.log(obj);
      }
      obj = null;
    }
    var arr = [true, false, null, undefined, NaN, 0, 1, {}, {}, 'a', 'a', NaN];
    // var arr = [0, 1, 1, 'a', 'a', 0];
    arr.unique();
    console.log(arr);
  </script>
</body>

</html>